home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
util
/
boot
/
loadppclib.lha
/
loadppclib
/
src
/
load040lib.e
next >
Wrap
Text File
|
2000-09-02
|
4KB
|
194 lines
-> FILE: ESrc:Own/load040lib.e REV: 1 --- load 68040.library on BlizzPPC
/* History
0 Started in September 2000.
*/
OPT PREPROCESS
#define VERSION 'load040lib 1.0.0 (2.9.2000)'
#define LIBNAME '68040.library'
MODULE 'dos/dos','dos/doshunks','exec/memory','exec/execbase',
'graphics/gfxbase','exec/resident'
ENUM ARG_LIB,ARG_FORCE,NUMARGS
ENUM ER_OK,ER_PARAM,ER_ALREADY,ER_NOBPPC,ER_LOADSEG,ER_NOTLIB,
ER_NOTPPCLIB,ER_ADDPPCLIB
DEF array[NUMARGS]:ARRAY OF LONG
PROC main() HANDLE
DEF attnflags
DEF rdargs = NIL, name:PTR TO CHAR, ioerr, ret
DEF r, pname[64]:STRING
DEF thelib, seglist = NIL, segment:PTR TO LONG, tag:PTR TO rt, seglen
DEF ids, islibrary = 0, isthelib = 0
IF (KickVersion(37) = 0)
WriteF('This program requires AmigaOS 2.04+\n')
RETURN RETURN_FAIL
ENDIF
attnflags := extattnflags(Int(execbase + $128))
IF ( ((attnflags AND AFF_68040) = 0) OR ((attnflags AND $80) <> 0) )
PrintF('This program requires 68040 CPU\n')
RETURN RETURN_FAIL
ENDIF
-> test if it's there already...
Forbid()
ids := FindName(execbase + 378, LIBNAME)
Permit()
IF (ids) THEN Raise(ER_ALREADY)
FOR r := 0 TO NUMARGS - 1; array[r] := 0; ENDFOR
IF ((rdargs := ReadArgs('LIBRARY,FORCE/S',
array, NIL)) = NIL) THEN Raise(ER_PARAM)
IF (array[ARG_LIB])
name := array[ARG_LIB]
ELSE
name := 'libs:' + LIBNAME
ENDIF
-> see if the HW is there...
Forbid()
ids := FindResident('BlizzardPPC.IDTag')
Permit()
IF ((ids = NIL) AND (array[ARG_FORCE] = 0)) THEN Raise(ER_NOBPPC)
-> load the seglist
IF ((seglist := LoadSeg(name)) = NIL) THEN Raise(ER_LOADSEG)
-> do the stuff in forbid...
Forbid()
IF (FindName(execbase + 378, LIBNAME) = NIL)
-> find the ROMTag in seglist
segment := seglist * 4
WHILE (seglist <> NIL) AND (segment <> NIL)
seglen := segment[-1] - 8 - SIZEOF rt
tag := segment + 2
WHILE (seglist <> NIL) AND (seglen > 0)
ADDQ.L #2,tag
SUBQ.L #2,seglen
IF ((tag.matchword = RTC_MATCHWORD) AND
(tag.matchtag) = tag)
islibrary := 1
-> check name
IF (StrCmp(tag.name, LIBNAME))
isthelib := 1
-> init the resident.
-> NOTE: emulates ROM-init with seglist = NIL
InitResident(tag, NIL)
-> did it work?
IF (FindName(execbase + 378, LIBNAME))
-> success! prevent unloading
seglist := NIL
ENDIF
ENDIF
ENDIF
ENDWHILE
segment := segment[] * 4
ENDWHILE
ENDIF
Permit()
IF (seglist)
IF (islibrary = 0) THEN Raise(ER_NOTLIB)
IF (isthelib = 0) THEN Raise(ER_NOTPPCLIB)
Raise(ER_ADDPPCLIB)
ENDIF
EXCEPT DO
IF (exception)
IF (ioerr := IoErr()) THEN PrintFault(ioerr, NIL)
GetProgramName(pname, StrMax(pname) - 1)
PrintF('\s: \s\s\n', pname,
ListItem(['', 'argument error',
'library already in memory',
'Blizzard PPC not found, FORCE to override',
'could not loadseg', 'file is not a library',
'file is not a ',
'could not add '
], exception),
IF ((exception = ER_NOTLIB) OR
(exception = ER_NOTPPCLIB)) THEN LIBNAME ELSE ''
)
ret := RETURN_ERROR
ELSE
ret := RETURN_OK
ENDIF
IF (seglist) THEN UnLoadSeg(seglist)
IF (rdargs) THEN FreeArgs(rdargs)
ENDPROC ret
CHAR '$VER: ',VERSION,0
PROC extattnflags(flags)
DEF orren = 0
IF ((flags AND AFF_68040) AND ((flags AND $80) = 0))
MOVE.L A5,-(A7)
LEA check040(PC),A5
JSR -$78(A6)
JSR -$1E(A6)
JSR -$7E(A6)
MOVE.L (A7)+,A5
MOVE.L D0,orren
ENDIF
RETURN flags OR orren
check040:
INT $4E7A,$8801 -> MOVEC VBR,A0
MOVE.L $10(A0),-(A7)
MOVE.L $2C(A0),-(A7)
MOVE.L A0,-(A7)
LEA c040illegal(PC),A1
MOVE.L A1,$10(A0)
MOVE.L A1,$2C(A0)
INT $F518,$F4F8,$F4D8
MOVEQ #0,D0
INT $4E7A,$0008 -> MOVEC BUSCR,D0
INT $4E7A,$0808 -> MOVEC PCR,D0
NOP
NOP
MOVEQ #1,D0
c040exit_illegal:
MOVE.L (A7)+,A0
MOVE.L (A7)+,$2C(A0)
MOVE.L (A7)+,$10(A0)
INT $F518,$F4F8,$F4D8
TST.L D0
BEQ.S c040_no040
MOVE.L #$00000080,D0
c040_no040:
NOP
RTE
c040illegal:
LEA c040exit_illegal(PC),A0
MOVE.L A0,2(A7)
NOP
RTE
ENDPROC